Skip to content

Fix race condition in project directory creation#358

Merged
cigamit merged 1 commit into
mainfrom
project_dir_lock
May 23, 2026
Merged

Fix race condition in project directory creation#358
cigamit merged 1 commit into
mainfrom
project_dir_lock

Conversation

@cigamit
Copy link
Copy Markdown
Contributor

@cigamit cigamit commented May 22, 2026

When testing with multiple task replicas I noticed this error

File "awx/main/tasks/jobs.py", line 380, in acquire_lock
os.mkdir(settings.PROJECTS_ROOT)
FileExistsError: [Errno 17] File exists: '/var/lib/awx/projects'

Looking upstream it was also just reported in ansible/awx#16456

This small change will fix the race condition. We already include in Pathlib, so a more modern fix might be

Path(settings.PROJECTS_ROOT).mkdir(parents=True, exist_ok=True)

but I will keep with what is currently the norm in the codebase for now.

@cigamit cigamit requested a review from TheWitness May 22, 2026 17:42
@cigamit cigamit self-assigned this May 22, 2026
Copilot AI review requested due to automatic review settings May 22, 2026 17:42
@cigamit cigamit added bug Something isn't working python Pull requests that update python code labels May 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a race condition when multiple task replicas attempt to create settings.PROJECTS_ROOT simultaneously, which could previously raise FileExistsError during project lock acquisition.

Changes:

  • Replace os.path.exists(...) + os.mkdir(...) with an atomic, idempotent directory creation call using os.makedirs(..., exist_ok=True).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cigamit cigamit merged commit 2c09058 into main May 23, 2026
1 check passed
@cigamit cigamit deleted the project_dir_lock branch May 23, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update python code

Development

Successfully merging this pull request may close these issues.

3 participants